#!/bin/sh

set -e

if ! git diff-index --quiet HEAD ; then
  echo there are files with uncommited changes. bailing.
  exit 1
fi

if ! (u="$(git ls-files --exclude-standard --others)" && test -z "$u"); then
  echo there are untracked files. bailing.
  exit 1
fi

DIR=releases
PACKAGE=${PWD##*/}
SHA=$(git rev-parse HEAD)
BUILD=${DIR}/${PACKAGE}.${SHA}
TARGET=s3://canary-releases

mkdir -p ${DIR}

godep go install
godep go build

mv ${PACKAGE} ${BUILD}

s3cmd put ${BUILD} ${TARGET}

echo release sha: ${SHA}
